#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <shadow.h>
#include <crypt.h>

int main(int argc, char * argv[])
{
	char * input_pass;
	char * crypted_pass;
	struct spwd * shadow_line;

	if(argc < 2)
	{
		printf("err\n");
		exit(1);
	}

	//安全地获取密码（无回显）
	input_pass = getpass("password:");
	//获取 用户的 spwd结构体
	shadow_line = getspnam(argv[1]);
	//把输入的密码进行加密
	crypted_pass = crypt(input_pass, shadow_line->sp_pwdp);
	//判断密码是否正确
	if(strcmp(shadow_line->sp_pwdp, crypted_pass) == 0)
	{
		printf("success\n");
	}
	else
	{
		printf("failed\n");
	}

	exit(0);
}
